<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="作业票ID" prop="ticketId">
        <el-input
          v-model="queryParams.ticketId"
          placeholder="请输入作业票ID"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="作业票名称" prop="ticketName">
        <el-input
          v-model="queryParams.ticketName"
          placeholder="请输入作业票名称"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="审批人ID" prop="approverId">
        <el-input
          v-model="queryParams.approverId"
          placeholder="请输入审批人ID"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="审批人名称" prop="approverName">
        <el-input
          v-model="queryParams.approverName"
          placeholder="请输入审批人名称"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="审批日期" prop="approvalDate">
        <el-date-picker clearable
          v-model="queryParams.approvalDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择审批日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="特种作业开始时间" prop="specialWorkTicketStartTime">
        <el-input
          v-model="queryParams.specialWorkTicketStartTime"
          placeholder="请输入备用字段1"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="特种作业结束时间" prop="specialWorkTicketEndTime">
        <el-input
          v-model="queryParams.specialWorkTicketEndTime"
          placeholder="请输入备用字段2"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="特种作业地点" prop="specialWorkTicketLocation">
        <el-input
          v-model="queryParams.specialWorkTicketLocation"
          placeholder="请输入备用字段3"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="特征那个作业操作员" prop="specialWorkTicketOperator">
        <el-input
          v-model="queryParams.specialWorkTicketOperator"
          placeholder="请输入备用字段4"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="备用字段5" prop="specialWorkTicketApprovalExtra5">
        <el-input
          v-model="queryParams.specialWorkTicketApprovalExtra5"
          placeholder="请输入备用字段5"
          clearable
          
        />
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" icon="search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['yanjing:approval:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['yanjing:approval:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['yanjing:approval:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['yanjing:approval:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="approvalList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="作业票ID" align="center" prop="ticketId" />
      <el-table-column label="作业票名称" align="center" prop="ticketName" />
      <el-table-column label="审批状态" align="center" prop="approvalStatus" />
      <el-table-column label="审批人ID" align="center" prop="approverId" />
      <el-table-column label="审批人名称" align="center" prop="approverName" />
      <el-table-column label="审批日期" align="center" prop="approvalDate" width="180"/>
      <el-table-column label="审批备注" align="center" prop="approvalRemark" />
      <el-table-column label="特种作业开始时间" align="center" prop="specialWorkTicketStartTime" width="180" />
      <el-table-column label="特种作业结束时间" align="center" prop="specialWorkTicketEndTime" width="180" />
      <el-table-column label="特种作业地点" align="center" prop="specialWorkTicketLocation" />
      <el-table-column label="特征那个作业操作员" align="center" prop="specialWorkTicketOperator" />
      <el-table-column label="备用字段5" align="center" prop="specialWorkTicketApprovalExtra5" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['yanjing:approval:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['yanjing:approval:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page.sync="queryParams.pageNum"
      v-model:limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改特种作业票审批信息对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="作业票ID" prop="ticketId">
          <el-input v-model="form.ticketId" placeholder="请输入作业票ID" />
        </el-form-item>
        <el-form-item label="作业票名称" prop="ticketName">
          <el-input v-model="form.ticketName" placeholder="请输入作业票名称" />
        </el-form-item>
        <el-form-item label="审批人ID" prop="approverId">
          <el-input v-model="form.approverId" placeholder="请输入审批人ID" />
        </el-form-item>
        <el-form-item label="审批人名称" prop="approverName">
          <el-input v-model="form.approverName" placeholder="请输入审批人名称" />
        </el-form-item>
        <el-form-item label="审批日期" prop="approvalDate">
          <el-date-picker clearable
            v-model="form.approvalDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择审批日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审批备注" prop="approvalRemark">
          <el-input v-model="form.approvalRemark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="特种作业开始时间" prop="specialWorkTicketStartTime">
          <el-input v-model="form.specialWorkTicketStartTime" placeholder="请输入备用字段1" />
        </el-form-item>
        <el-form-item label="特种作业结束时间" prop="specialWorkTicketEndTime">
          <el-input v-model="form.specialWorkTicketEndTime" placeholder="请输入备用字段2" />
        </el-form-item>
        <el-form-item label="特种作业地点" prop="specialWorkTicketLocation">
          <el-input v-model="form.specialWorkTicketLocation" placeholder="请输入备用字段3" />
        </el-form-item>
        <el-form-item label="特征那个作业操作员" prop="specialWorkTicketOperator">
          <el-input v-model="form.specialWorkTicketOperator" placeholder="请输入备用字段4" />
        </el-form-item>
        <el-form-item label="备用字段5" prop="specialWorkTicketApprovalExtra5">
          <el-input v-model="form.specialWorkTicketApprovalExtra5" placeholder="请输入备用字段5" />
        </el-form-item>
        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listApproval, getApproval, delApproval, addApproval, updateApproval } from "@/api/business/approval";

export default {
  name: "Approval",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 特种作业票审批信息表格数据
      approvalList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ticketId: null,
        ticketName: null,
        approvalStatus: null,
        approverId: null,
        approverName: null,
        approvalDate: null,
        approvalRemark: null,
        specialWorkTicketStartTime: null,
        specialWorkTicketEndTime: null,
        specialWorkTicketLocation: null,
        specialWorkTicketOperator: null,
        specialWorkTicketApprovalExtra5: null,
        createId: null,
        createName: null,
        updateId: null,
        updateName: null,
        accountId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        approverId: [
          { required: true, message: "审批人ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询特种作业票审批信息列表 */
    getList() {
      this.loading = true;
      listApproval(this.queryParams).then(response => {
        this.approvalList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        ticketId: null,
        ticketName: null,
        approvalStatus: null,
        approverId: null,
        approverName: null,
        approvalDate: null,
        approvalRemark: null,
        specialWorkTicketStartTime: null,
        specialWorkTicketEndTime: null,
        specialWorkTicketLocation: null,
        specialWorkTicketOperator: null,
        specialWorkTicketApprovalExtra5: null,
        createId: null,
        createName: null,
        createTime: null,
        updateId: null,
        updateName: null,
        updateTime: null,
        accountId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加特种作业票审批信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getApproval(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改特种作业票审批信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateApproval(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addApproval(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除特种作业票审批信息编号为"' + ids + '"的数据项？').then(function() {
        return delApproval(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('yanjing/approval/export', {
        ...this.queryParams
      }, `approval_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
